<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable, HasRoles;

    protected $guard_name = ['sanctum'];

    protected $fillable = [
        'name',
        'email',
        'mobile',
        'password',
    ];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array<int, string>
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * The attributes that should be cast.
     *
     * @var array<string, string>
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];


    public function attachments()
    {
        return $this->morphMany(Attachment::class, 'attachmentable');
    }


    // 关联投诉(作为管理员)
    public function replyReports()
    {
        return $this->morphMany(Report::class, 'reportable');
    }

    // 关联诉求表(作为管理员)
    public function replyAppeals()
    {
        return $this->morphMany(Appeal::class, 'appealable');
    }

    // 关联政策咨询(作为管理员)
    public function replyConsultations()
    {
        return $this->morphMany(Consultation::class, 'consultationable');
    }

}
